home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / a_to_d / dbfilt15 / fltdemo1.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  5KB  |  145 lines

  1. unit Fltdemo1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, DBTables, DB, Grids, DBGrids,
  8.   StdCtrls, Buttons, DBFiltUZ, VisApp;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.      Database1: TDatabase;
  13.      Table1: TTable;
  14.      DataSource1: TDataSource;
  15.      DBGrid1: TDBGrid;
  16.      UZFilter1: TUZFilter;
  17.      BitBtn2: TBitBtn;
  18.      Table2: TTable;
  19.      GroupBox1: TGroupBox;
  20.      CheckBox1: TCheckBox;
  21.     DataSource2: TDataSource;
  22.      DBGrid2: TDBGrid;
  23.     UZFilter2: TUZFilter;
  24.     GroupBox2: TGroupBox;
  25.      CheckBox2: TCheckBox;
  26.      Table2OrderNo: TFloatField;
  27.      Table2CustNo: TFloatField;
  28.      Table2ItemsTotal: TCurrencyField;
  29.      Table2SaleDate: TDateTimeField;
  30.      Table2ShipDate: TDateTimeField;
  31.      function UZFilter1FilterRecord(Sender: TObject; RecNo: Longint;
  32.         DataSet: TDataset): Boolean;
  33.      function UZFilter2FilterRecord(Sender: TObject; RecNo: Longint;
  34.         DataSet: TDataset): Boolean;
  35.      procedure CheckBox1Click(Sender: TObject);
  36.      procedure CheckBox2Click(Sender: TObject);
  37.      procedure FormActivate(Sender: TObject);
  38.      procedure CheckBoxSetDisplay;
  39.   private
  40.      { Private declarations }
  41.   public
  42.      { Public declarations }
  43.   end;
  44.  
  45. var
  46.   Form1: TForm1;
  47.  
  48. implementation
  49.  
  50. {$R *.DFM}
  51.  
  52. {---------------------------------------------------------------------------
  53. *  Here it is, the callback function used to filter the TTable/TDataSet
  54. *
  55. *  NOTE:        though it seems trivial, here is done something, which wouldn't
  56. *                be possible with DELPHI renages/filtering, because the
  57. *                FILTER-FIELD is NOT THE INDEXED FIILD
  58. *
  59. *    ALL YOU HAVE TO CODE IS THIS !!!
  60. *
  61. *---------------------------------------------------------------------------}
  62. function TForm1.UZFilter1FilterRecord(Sender: TObject; RecNo: Longint;
  63.                                           DataSet: TDataset): Boolean;
  64. begin
  65.     Result := (DataSet.FieldByName('CustNo').AsInteger > 1500) and
  66.                  (DataSet.FieldByName('CustNo').AsInteger < 2200);
  67. end;
  68.  
  69. {---------------------------------------------------------------------------
  70. *  this is the filter callback for the detail table ORDERS
  71. *
  72. *  NOTE:    ->    the filters are INDEPENDANT from each other
  73. *            ->    if using a mastersourced (linked) DataSource, the DATAIL-checks
  74. *                go HEREIN !!
  75. *
  76. *    ALL YOU HAVE TO CODE IS THIS !!!
  77. *
  78. *---------------------------------------------------------------------------}
  79. function TForm1.UZFilter2FilterRecord(Sender: TObject; RecNo: Longint;
  80.                                           DataSet: TDataset): Boolean;
  81. begin
  82.     Result := (DataSet.FieldByName('ItemsTotal').AsInteger > 5000);
  83. end;
  84.  
  85.  
  86. {---------------------------------------------------------------------------
  87. *  all the other stuff is just to get a proper outfit for the demo
  88. *---------------------------------------------------------------------------}
  89. procedure TForm1.CheckBox1Click(Sender: TObject);
  90. begin
  91.     UZFilter1.Active := not(UZFilter1.Active);{ just switch the filter on/off }
  92.     CheckBoxSetDisplay;                                { update diplay for CheckBoxes }
  93.     {---------------------------------------------------------------------------
  94.     *    you might try these, but before doing so, 'please examine the DBFILTUZ.INT
  95.     *    CAREFULLY to check specially the security functions
  96.     *---------------------------------------------------------------------------}
  97. (*    DataSource1.DataSet.Active :=              { switch the dataset active-mode }
  98.         not(DataSource1.DataSet.Active);            *)
  99. (*    Table3.Active := true;                           { switch to another table }
  100.     DataSource1.DataSet := Table3;                { NOTE: must add another TTable first !! }
  101.                                                             *)
  102.  
  103. (*    UZFilter1.DataSource := nil;                    { kill filter's datasource }
  104.                                                             *)
  105. end;
  106.  
  107. procedure TForm1.CheckBox2Click(Sender: TObject);
  108. begin
  109.     UZFilter2.Active := not(UZFilter2.Active);{ just switch the filter on/off }
  110.     CheckBoxSetDisplay;                                { update diplay for CheckBoxes }
  111. end;
  112.  
  113. procedure TForm1.CheckBoxSetDisplay;
  114. begin
  115.     with CheckBox1 do begin                            { all on CheckBox1 }
  116.         If UZFilter1.Active then begin            { is the filter active ? }
  117.             Caption := '1500 > CustNo < 2200';
  118.             Font.Color := clLime;
  119.             Checked := true;
  120.         end else begin                                 { ! no inactive }
  121.             Caption := 'inactive';
  122.             Font.Color := clRed;
  123.             Checked := false;
  124.         end;                                                { ? UZFilter2 active }
  125.     end;                                                    { with CheckBox1 }
  126.     with CheckBox2 do begin                            { all on CheckBox1 }
  127.         If UZFilter2.Active then begin            { is the filter active ? }
  128.             Caption := 'ItemsTotal > 5000';
  129.             Font.Color := clLime;
  130.             Checked := true;
  131.         end else begin                                 { ! no inactive }
  132.             Caption := 'inactive';
  133.             Font.Color := clRed;
  134.             Checked := false;
  135.         end;                                                { ? UZFilter1 active }
  136.     end;                                                    { with CheckBox1 }
  137. end;
  138.  
  139. procedure TForm1.FormActivate(Sender: TObject);
  140. begin
  141.     CheckBoxSetDisplay;                                { update display for CheckBoxes }
  142. end;
  143.  
  144. end.
  145.